home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
hity wydania
/
trueSpace 7.6
/
tS761B8Std.exe
/
{app}
/
Scripts
/
D3D
/
RsD3DMaterialFromME2_Template.fx
< prev
next >
Wrap
Text File
|
2008-06-10
|
27KB
|
756 lines
#line 3 "MainD3DShaderTemplate"
//----------------------------------------------------------------------
//END - The custom shader code
//----------------------------------------------------------------------
//----------------------------------------------------------------------
//Basic shader template + vertex shader (or hw skinning) enabled shadows
//
//Author - Michal Valient
//Copyright (C) 2004-2008 Caligari corporation
//
//----------------------------------------------------------------------
/*****
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
If you make changes here, you have to make sure you modify shadow mapping techique the same way!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*****/
uniform float RsD3DMaterialFromME_fNormalMod = 1.0f;
uniform float RsD3DMaterialFromME_fOpacity = 1.0f;
uniform float4 RsD3DMaterialFromME_cOverlayMod = { 0.0f, 0.0f, 0.0f, 1.0f };
#ifdef RsShaderHWSKINNING
#define SKIN_INDEX_SHIFT 0.001960784313725490196078431372549f
float4x3 RsD3DMaterialFromME_mSkinMatrices[RTD3DMESH_MAXIMUM_BONE_COUNT];
#endif //RsShaderHWSKINNING
D3_VERTEXOUTPUT RsD3DMaterialFromME_VertexShader( in RtFloat4 D3_pInputPosition : POSITION,
in RtFloat3 D3_vInputNormal : NORMAL,
in RtFloat3 D3_vInputTangent : TANGENT,
in float2 D3_vInputTexCoords1 : TEXCOORD0,
in float2 D3_vInputTexCoords2 : TEXCOORD1,
in RtFloat4 D3_cInputColor : COLOR0
#ifdef RsShaderHWSKINNING
, in RtFloat4 D3_vInputBlendIndices : BLENDINDICES
, in RtFloat4 D3_cInputBlendWeight : BLENDWEIGHT
#endif //RsShaderHWSKINNING
)
{
///First perform default transformation pipeline
float3 vCoord1 = 0;
float3 vCoord2 = 0;
vCoord1.xy = D3_vInputTexCoords1;
vCoord2.xy = D3_vInputTexCoords2;
float4 local_vertex_position;
float3 local_normal;
float3 local_tangent;
#ifdef RsShaderHWSKINNING
float3 tmp_position = 0;
local_normal = 0.0f;
local_tangent = 0.0f;
//Get the blend weights
float4 blend_weights = (255.0f/127.0f)*D3_cInputBlendWeight - (128.0f / 127.0f);
float4 blend_indices = D3_vInputBlendIndices * 255.0f + SKIN_INDEX_SHIFT;
/// Skin it!
for (int bone_idx = 0; bone_idx<4; bone_idx++)
{
int matrix_idx = (int)blend_indices[bone_idx];
float weight = blend_weights[bone_idx];
float3 bone_position = weight*mul(D3_pInputPosition, RsD3DMaterialFromME_mSkinMatrices[matrix_idx]);
float3 bone_normal = weight*mul(D3_vInputNormal, RsD3DMaterialFromME_mSkinMatrices[matrix_idx]);
float3 bone_tangent = weight*mul(D3_vInputTangent, RsD3DMaterialFromME_mSkinMatrices[matrix_idx]);
tmp_position += bone_position;
local_normal += bone_normal;
local_tangent += bone_tangent;
}
local_vertex_position.xyz = tmp_position.xyz;
local_vertex_position.w = 1.0f;
#else
local_vertex_position = D3_pInputPosition;
local_normal = D3_vInputNormal;
local_tangent = D3_vInputTangent;
#endif //RsShaderHWSKINNING
float4 pVertexPosition = mul(local_vertex_position, D3_mObjectToWorld);
float3 vEyeTmp = D3_pEye - pVertexPosition;
float fEyeDist = length(vEyeTmp);
float3 vEye = normalize(vEyeTmp);
//Flip the normal and tangent direction if we are processing the backface here
float3 vInputNormal = RsD3DMaterialFromME_fNormalMod * local_normal;
float3 vInputTangent = RsD3DMaterialFromME_fNormalMod * local_tangent;
float3x3 mToTangentTmp;
mToTangentTmp[0] = vInputTangent;
mToTangentTmp[2] = vInputNormal;
mToTangentTmp[1] = cross(vInputTangent, vInputNormal); //The cross product to compute binormal NxT
float3x3 mTangentToWorld = mul(mToTangentTmp, D3_mObjectToWorldN);
//------------------------------
//Perform default processing on variables
rsxi_VarShaderInput;
tsxi_SetInputTangentToWorld(mTangentToWorld);
tsxi_SetInputTexCoords1(vCoord1);
tsxi_SetInputTexCoords2(vCoord2);
tsxi_SetInputTangent(mTangentToWorld[0]);
tsxi_SetInputNormal(mTangentToWorld[2]);
tsxi_SetInputColor(D3_cInputColor);
tsxi_SetInputAlpha(D3_cInputColor.a);
tsxi_SetInputPosition(pVertexPosition);
tsxi_SetInputEyePos(D3_pEye);
tsxi_SetInputEyeDir(vEye);
tsxi_SetInputEyeDist(fEyeDist);
tsxi_SetInputLightDir(vEye);
tsxi_SetInputLightDist(fEyeDist);
tsxi_SetInputLightColor(RtFloat4(1,1,1,1));
#ifdef RsShaderVSVERTEXSHADER
RtFloat4 vTmpPos = tsxi_GetInputPosition;
RtFloat4 vTmpCol = tsxi_GetInputColor;
RtFloat3 vTmpNorm = tsxi_GetInputNormal;
RtFloat3 vTmpTang = tsxi_GetInputTangent;
RsShaderVSVERTEXSHADER(rsxi_SendShaderInput, vTmpPos, vTmpCol, vTmpNorm, vTmpTang);
tsxi_SetInputPosition(vTmpPos);
tsxi_SetInputColor(vTmpCol);
tsxi_SetInputNormal(vTmpNorm);
tsxi_SetInputTangent(vTmpTang);
//Eye, light and tangent matrices have to be recomputed now
vEyeTmp = D3_pEye - vTmpPos;
fEyeDist = length(vEye);
vEye = normalize(vEyeTmp);
mTangentToWorld[0] = vTmpTang;
mTangentToWorld[2] = vTmpNorm;
mTangentToWorld[1] = cross(vTmpTang, vTmpNorm); //The cross product to compute binormal NxT
tsxi_SetInputEyeDir(vEye);
tsxi_SetInputEyeDist(fEyeDist);
tsxi_SetInputLightDir(vEye);
tsxi_SetInputLightDist(fEyeDist);
tsxi_SetInputTangentToWorld(mTangentToWorld);
#endif
#ifdef RsShaderVSTEXCOORD
RtFloat3 vTmpTexCrd1 = tsxi_GetInputTexCoords1;
RtFloat3 vTmpTexCrd2 = tsxi_GetInputTexCoords2;
RsShaderVSTEXCOORD(rsxi_SendShaderInput, vTmpTexCrd1, vTmpTexCrd2);
tsxi_SetInputTexCoords1(vTmpTexCrd1);
tsxi_SetInputTexCoords2(vTmpTexCrd2);
#endif
#ifdef RsShaderVSLIGHT
RtFloat4 vTmpLightColor = tsxi_GetInputLightColor;
RtFloat3 vTmpLightDir = tsxi_GetInputLightDir;
RtFloat vTmpLightDist = tsxi_GetInputLightDist;
RsShaderVSLIGHT(rsxi_SendShaderInput, vTmpLightColor, vTmpLightDir, vTmpLightDist);
tsxi_SetInputLightColor(vTmpLightColor);
tsxi_SetInputLightDir(normalize(vTmpLightDir));
tsxi_SetInputLightDist(vTmpLightDist);
#endif
D3_VERTEXOUTPUT Output;
#if ((defined(RsShaderVSVERTEXSHADER)) || (defined(RsShaderHWSKINNING)))
///If we have vertex shader we need to use world position produced by position shader
Output.D3_pClipPosition = mul(tsxi_GetInputPosition, D3_mWorldToClip);
#else
///Otherwise we use clip position which is faster and more precise.
Output.D3_pClipPosition = mul(local_vertex_position, D3_mObjectToClip);
#endif
Output.D3_vVertexTexCoords.xy = tsxi_GetInputTexCoords1.xy;
Output.D3_vVertexTexCoords.wz = tsxi_GetInputTexCoords2.xy;
Output.D3_pVertexPosition = tsxi_GetInputPosition;
Output.D3_vEye.xyz = tsxi_GetInputEyeDir;
Output.D3_vEye.w = tsxi_GetInputEyeDist;
Output.D3_mToWorld = tsxi_GetInputTangentToWorld;
Output.D3_vLightVector.xyz = tsxi_GetInputLightDir;
Output.D3_vLightVector.w = tsxi_GetInputLightDist;
Output.D3_cLightColor = tsxi_GetInputLightColor;
Output.D3_cVertexColor = tsxi_GetInputColor;
return Output;
}
D3_PIXELOUTPUT RsD3DMaterialFromME_PixelShader(uniform bool IsFirstPass,
in D3_PIXELINPUT Input)
{
D3_PIXELOUTPUT Output;
rsxi_VarShaderInput;
//------------------------------
//Perform default processing on variables
tsxi_SetInputTangentToWorld(Input.D3_mToWorld);
tsxi_SetInputTexCoords1(Input.D3_vVertexTexCoords.xyzw);
tsxi_SetInputTexCoords2(Input.D3_vVertexTexCoords.wzyx);
tsxi_SetInputTangent(Input.D3_mToWorld[0]);
tsxi_SetInputNormal(Input.D3_mToWorld[2]);
tsxi_SetInputColor(Input.D3_cVertexColor);
tsxi_SetInputAlpha(Input.D3_cVertexColor.a);
tsxi_SetInputPosition(Input.D3_pVertexPosition);
tsxi_SetInputEyePos(D3_pEye);
tsxi_SetInputEyeDist(Input.D3_vEye.w);
tsxi_SetInputEyeDir(rtx_CubeNormalize(Input.D3_vEye.xyz));
tsxi_SetInputLightDist(Input.D3_vLightVector.w);
tsxi_SetInputLightDir(Input.D3_vLightVector.xyz);
tsxi_SetInputLightColor(Input.D3_cLightColor);
#ifdef RsShaderNORMAL
RtFloat3 vTmpNormal = tsxi_GetInputNormal;
RtFloat3 vTmpTangent = tsxi_GetInputTangent;
RsShaderNORMAL(rsxi_SendShaderInput, vTmpNormal, vTmpTangent);
tsxi_SetInputNormal(normalize(vTmpNormal));
tsxi_SetInputTangent(rtx_CubeNormalize(vTmpTangent));
#else
tsxi_SetInputNormal(rtx_CubeNormalize(tsxi_GetInputNormal));
tsxi_SetInputTangent(rtx_CubeNormalize(tsxi_GetInputTangent));
#endif
#ifdef RsShaderALPHA
RtFloat fTmpAlpha = tsxi_GetInputAlpha;
RsShaderALPHA(rsxi_SendShaderInput, fTmpAlpha);
tsxi_SetInputAlpha(fTmpAlpha);
#endif
#ifdef RsShaderCOLOR
RtFloat4 vTmpColor = tsxi_GetInputColor;
RsShaderCOLOR(rsxi_SendShaderInput, vTmpColor);
tsxi_SetInputColor(vTmpColor);
#endif
#ifdef RsShaderLIGHT
RtFloat4 vTmpLightColor = tsxi_GetInputLightColor;
RtFloat3 vTmpLightDir = tsxi_GetInputLightDir;
RtFloat fTmpLightDist = tsxi_GetInputLightDist;
RsShaderLIGHT(rsxi_SendShaderInput, vTmpLightColor, vTmpLightDir, fTmpLightDist);
tsxi_SetInputLightColor(vTmpLightColor);
tsxi_SetInputLightDist(fTmpLightDist);
tsxi_SetInputLightDir(rtx_CubeNormalize(vTmpLightDir));
#else
RtFloat3 vTmpLightDir = tsxi_GetInputLightDir;
tsxi_SetInputLightDir(rtx_CubeNormalize(vTmpLightDir));
#endif
RtFloat4 vTmpOutColor = tsxi_GetInputColor;
#ifdef RsShaderMODEL
RsShaderMODEL(rsxi_SendShaderInput, vTmpOutColor);
#else
vTmpOutColor.xyz = tsxi_GetInputColor * tsxi_GetInputLightColor * saturate(dot(tsxi_GetInputLightDir, tsxi_GetInputNormal));
#endif
#ifdef RsShaderCONSTANT
if (IsFirstPass)
{
RtFloat4 vTmpConstantColor = 0.0f;
RsShaderCONSTANT(rsxi_SendShaderInput, vTmpConstantColor);
vTmpOutColor.xyz += vTmpConstantColor; /// Append the constant color if available
}
#endif
///Add the overlay color
if (IsFirstPass)
{
///First pass performs complete blending.
vTmpOutColor.xyz = RsD3DMaterialFromME_cOverlayMod.xyz + RsD3DMaterialFromME_cOverlayMod.a * vTmpOutColor.xyz;
}
else
{
///All other passes just attenuate the lighting accordingly.
vTmpOutColor.xyz = RsD3DMaterialFromME_cOverlayMod.a * vTmpOutColor.xyz;
}
#ifdef RsShaderALPHA
vTmpOutColor.a = saturate(vTmpOutColor.a * RsD3DMaterialFromME_fOpacity);
#else
vTmpOutColor.a = saturate(RsD3DMaterialFromME_fOpacity);
#endif
Output.D3_cOutColor = vTmpOutColor;
return Output;
}
pixelshader RsD3DMaterialFromME_PixelShader_ps_2_0_P1 = compile ME_PS_PROFILE RsD3DMaterialFromME_PixelShader(true);
pixelshader RsD3DMaterialFromME_PixelShader_ps_2_0_P2 = compile ME_PS_PROFILE RsD3DMaterialFromME_PixelShader(false);
pixelshader RsD3DMaterialFromME_PixelShader_ps_2_0_Opaque_P1 = compile ME_PS_PROFILE RsD3DMaterialFromME_PixelShader(true);
pixelshader RsD3DMaterialFromME_PixelShader_ps_2_0_Opaque_P2 = compile ME_PS_PROFILE RsD3DMaterialFromME_PixelShader(false);
vertexshader RsD3DMaterialFromME_VertexShader_vs_2_0 = compile ME_VS_PROFILE RsD3DMaterialFromME_VertexShader();
//------------------------------
// Techniques
// This is automatically generated code
//------------------------------
//
technique D3_MAIN_TECHNIQUE_OPAQUE
<
string Rs_TechniqueMode = "firstlight";
string Rs_TechniqueOpacity = "opaque";
string Rs_TechniqueQuality = "95";
>
{
pass D3_PASS_01
{
VertexShader = (RsD3DMaterialFromME_VertexShader_vs_2_0);
PixelShader = (RsD3DMaterialFromME_PixelShader_ps_2_0_Opaque_P1);
AlphaBlendEnable = false;
ZEnable = true;
ZFunc = LESSEQUAL;
ZWriteEnable = true;
CullMode = CCW;
}
}
technique D3_MAIN_TECHNIQUE_OPAQUE_MOREPASSES
<
string Rs_TechniqueMode = "morelights";
string Rs_TechniqueOpacity = "opaque";
string Rs_TechniqueQuality = "95";
>
{
pass D3_PASS_01
{
VertexShader = (RsD3DMaterialFromME_VertexShader_vs_2_0);
PixelShader = (RsD3DMaterialFromME_PixelShader_ps_2_0_Opaque_P2);
AlphaBlendEnable = true;
SrcBlend = ONE;
DestBlend = ONE;
ZEnable = true;
ZFunc = LESSEQUAL;
ZWriteEnable = false;
CullMode = CCW;
}
}
technique D3_MAIN_TECHNIQUE
<
string Rs_TechniqueMode = "firstlight";
string Rs_TechniqueOpacity = "transparent";
string Rs_TechniqueQuality = "95";
>
{
pass D3_PASS_01
{
VertexShader = (RsD3DMaterialFromME_VertexShader_vs_2_0);
PixelShader = (RsD3DMaterialFromME_PixelShader_ps_2_0_P1);
AlphaBlendEnable = true;
SrcBlend = SRCALPHA;
DestBlend = INVSRCALPHA;
ZEnable = true;
ZFunc = LESSEQUAL;
ZWriteEnable = false;
}
}
technique D3_MAIN_TECHNIQUE_MOREPASSES
<
string Rs_TechniqueMode = "morelights";
string Rs_TechniqueOpacity = "transparent";
string Rs_TechniqueQuality = "95";
>
{
pass D3_PASS_01
{
VertexShader = (RsD3DMaterialFromME_VertexShader_vs_2_0);
PixelShader = (RsD3DMaterialFromME_PixelShader_ps_2_0_P2);
AlphaBlendEnable = true;
SrcBlend = SRCALPHA;
DestBlend = ONE;
ZEnable = true;
ZFunc = LESSEQUAL;
ZWriteEnable = false;
}
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
//----------------------------------------------------------------------
// Shadow mapping support
//----------------------------------------------------------------------
//----------------------------------------------------------------------
//----------------------------------------------------------------------
///Shadow uniforms - keep in sync with RsD3DShadowMapRT2.fx
uniform float fShadowBias;
uniform float fKillThresholdValue;
//structures
typedef struct
{
RtFloat4 D3_pInputPosition : POSITION;
RtFloat3 D3_vInputNormal : NORMAL;
RtFloat3 D3_vInputTangent : TANGENT;
float2 D3_vInputTexCoords1 : TEXCOORD0;
float2 D3_vInputTexCoords2 : TEXCOORD1;
RtFloat4 D3_cInputColor : COLOR0;
} D3_SHADOW_VERTEXINPUT;
typedef struct
{
RtFloat4 D3_pClipPosition : POSITION;
RtFloat4 D3_vVertexTexCoords : TEXCOORD0;
RtFloat4 D3_pVertexPosition : TEXCOORD1;
RtFloat3x3 D3_mToWorld : TEXCOORD2;
RtFloat4 D3_vEye : TEXCOORD5;
RtFloat4 D3_pClipPosition2 : TEXCOORD6;
RtFloat4 D3_cVertexColor : COLOR0;
} D3_SHADOW_VERTEXOUTPUT;
typedef struct {
RtFloat4 D3_vVertexTexCoords : TEXCOORD0;
RtFloat4 D3_pVertexPosition : TEXCOORD1;
RtFloat3x3 D3_mToWorld : TEXCOORD2;
RtFloat4 D3_vEye : TEXCOORD5;
RtFloat4 D3_pClipPosition2 : TEXCOORD6;
RtFloat4 D3_cVertexColor : COLOR0;
} D3_SHADOW_PIXELINPUT;
typedef struct {
float4 D3_cOutColor : COLOR0;
} D3_SHADOW_PIXELOUTPUT;
D3_SHADOW_VERTEXOUTPUT RsD3DMaterialFromME_Shadow_VertexShader( in RtFloat4 D3_pInputPosition : POSITION,
in RtFloat3 D3_vInputNormal : NORMAL,
in RtFloat3 D3_vInputTangent : TANGENT,
in float2 D3_vInputTexCoords1 : TEXCOORD0,
in float2 D3_vInputTexCoords2 : TEXCOORD1,
in RtFloat4 D3_cInputColor : COLOR0
#ifdef RsShaderHWSKINNING
, in RtFloat4 D3_vInputBlendIndices : BLENDINDICES
, in RtFloat4 D3_cInputBlendWeight : BLENDWEIGHT
#endif //RsShaderHWSKINNING
)
{
///First perform default transformation pipeline
float3 vCoord1 = 0;
float3 vCoord2 = 0;
vCoord1.xy = D3_vInputTexCoords1;
vCoord2.xy = D3_vInputTexCoords2;
float4 local_vertex_position;
float3 local_normal;
float3 local_tangent;
#ifdef RsShaderHWSKINNING
float3 tmp_position = 0;
local_normal = 0.0f;
local_tangent = 0.0f;
//Get the blend weights
float4 blend_weights = (255.0f/127.0f)*D3_cInputBlendWeight - (128.0f / 127.0f);
float4 blend_indices = D3_vInputBlendIndices * 255.0f + SKIN_INDEX_SHIFT;
/// Skin it!
for (int bone_idx = 0; bone_idx<4; bone_idx++)
{
int matrix_idx = (int)blend_indices[bone_idx];
float weight = blend_weights[bone_idx];
float3 bone_position = weight*mul(D3_pInputPosition, RsD3DMaterialFromME_mSkinMatrices[matrix_idx]);
float3 bone_normal = weight*mul(D3_vInputNormal, RsD3DMaterialFromME_mSkinMatrices[matrix_idx]);
float3 bone_tangent = weight*mul(D3_vInputTangent, RsD3DMaterialFromME_mSkinMatrices[matrix_idx]);
tmp_position += bone_position;
local_normal += bone_normal;
local_tangent += bone_tangent;
}
local_vertex_position.xyz = tmp_position.xyz;
local_vertex_position.w = 1.0f;
#else
local_vertex_position = D3_pInputPosition;
local_normal = D3_vInputNormal;
local_tangent = D3_vInputTangent;
#endif //RsShaderHWSKINNING
float4 pVertexPosition = mul(local_vertex_position, D3_mObjectToWorld);
float3 vEyeTmp = D3_pEye - pVertexPosition;
float fEyeDist = length(vEyeTmp);
float3 vEye = normalize(vEyeTmp);
//Flip the normal and tangent direction if we are processing the backface here
float3 vInputNormal = RsD3DMaterialFromME_fNormalMod * local_normal;
float3 vInputTangent = RsD3DMaterialFromME_fNormalMod * local_tangent;
float3x3 mToTangentTmp;
mToTangentTmp[0] = vInputTangent;
mToTangentTmp[2] = vInputNormal;
mToTangentTmp[1] = cross(vInputTangent, vInputNormal); //The cross product to compute binormal NxT
float3x3 mTangentToWorld = mul(mToTangentTmp, D3_mObjectToWorldN);
//------------------------------
//Perform default processing on variables
rsxi_VarShaderInput;
tsxi_SetInputTangentToWorld(mTangentToWorld);
tsxi_SetInputTexCoords1(vCoord1);
tsxi_SetInputTexCoords2(vCoord2);
tsxi_SetInputTangent(mTangentToWorld[0]);
tsxi_SetInputNormal(mTangentToWorld[2]);
tsxi_SetInputColor(D3_cInputColor);
tsxi_SetInputAlpha(D3_cInputColor.a);
tsxi_SetInputPosition(pVertexPosition);
tsxi_SetInputEyePos(D3_pEye);
tsxi_SetInputEyeDir(vEye);
tsxi_SetInputEyeDist(fEyeDist);
tsxi_SetInputLightDir(vEye);
tsxi_SetInputLightDist(fEyeDist);
tsxi_SetInputLightColor(RtFloat4(1,1,1,1));
#ifdef RsShaderVSVERTEXSHADER
RtFloat4 vTmpPos = tsxi_GetInputPosition;
RtFloat4 vTmpCol = tsxi_GetInputColor;
RtFloat3 vTmpNorm = tsxi_GetInputNormal;
RtFloat3 vTmpTang = tsxi_GetInputTangent;
RsShaderVSVERTEXSHADER(rsxi_SendShaderInput, vTmpPos, vTmpCol, vTmpNorm, vTmpTang);
tsxi_SetInputPosition(vTmpPos);
tsxi_SetInputColor(vTmpCol);
tsxi_SetInputNormal(vTmpNorm);
tsxi_SetInputTangent(vTmpTang);
//Eye, light and tangent matrices have to be recomputed now
vEyeTmp = D3_pEye - vTmpPos;
fEyeDist = length(vEye);
vEye = normalize(vEyeTmp);
mTangentToWorld[0] = vTmpTang;
mTangentToWorld[2] = vTmpNorm;
mTangentToWorld[1] = cross(vTmpTang, vTmpNorm); //The cross product to compute binormal NxT
tsxi_SetInputEyeDir(vEye);
tsxi_SetInputEyeDist(fEyeDist);
tsxi_SetInputLightDir(vEye);
tsxi_SetInputLightDist(fEyeDist);
tsxi_SetInputTangentToWorld(mTangentToWorld);
#endif
#ifdef RsShaderVSTEXCOORD
RtFloat3 vTmpTexCrd1 = tsxi_GetInputTexCoords1;
RtFloat3 vTmpTexCrd2 = tsxi_GetInputTexCoords2;
RsShaderVSTEXCOORD(rsxi_SendShaderInput, vTmpTexCrd1, vTmpTexCrd2);
tsxi_SetInputTexCoords1(vTmpTexCrd1);
tsxi_SetInputTexCoords2(vTmpTexCrd2);
#endif
D3_SHADOW_VERTEXOUTPUT Output;
#if ((defined(RsShaderVSVERTEXSHADER)) || (defined(RsShaderHWSKINNING)))
///If we have vertex shader we need to use world position produced by position shader
Output.D3_pClipPosition = mul(tsxi_GetInputPosition, D3_mWorldToClip);
#else
///Otherwise we use clip position which is faster and more precise.
Output.D3_pClipPosition = mul(local_vertex_position, D3_mObjectToClip);
#endif
Output.D3_pClipPosition2 = Output.D3_pClipPosition;
Output.D3_vVertexTexCoords.xy = tsxi_GetInputTexCoords1.xy;
Output.D3_vVertexTexCoords.wz = tsxi_GetInputTexCoords2.xy;
Output.D3_pVertexPosition = tsxi_GetInputPosition;
Output.D3_vEye.xyz = tsxi_GetInputEyeDir;
Output.D3_vEye.w = tsxi_GetInputEyeDist;
Output.D3_mToWorld = tsxi_GetInputTangentToWorld;
Output.D3_cVertexColor = tsxi_GetInputColor;
return Output;
}
#define SHADOW_QUALITY_LQ 1
#define SHADOW_QUALITY_MQ 2
#define SHADOW_QUALITY_HQ 3
D3_SHADOW_PIXELOUTPUT RsD3DMaterialFromME_Shadow_PixelShader(uniform int inShadowQuality,
in D3_SHADOW_PIXELINPUT Input)
{
D3_SHADOW_PIXELOUTPUT Output;
rsxi_VarShaderInput;
//------------------------------
//Perform default processing on variables
tsxi_SetInputTangentToWorld(Input.D3_mToWorld);
tsxi_SetInputTexCoords1(Input.D3_vVertexTexCoords.xyzw);
tsxi_SetInputTexCoords2(Input.D3_vVertexTexCoords.wzyx);
tsxi_SetInputTangent(Input.D3_mToWorld[0]);
tsxi_SetInputNormal(Input.D3_mToWorld[2]);
tsxi_SetInputColor(Input.D3_cVertexColor);
tsxi_SetInputAlpha(Input.D3_cVertexColor.a);
tsxi_SetInputPosition(Input.D3_pVertexPosition);
tsxi_SetInputEyePos(D3_pEye);
tsxi_SetInputEyeDist(Input.D3_vEye.w);
tsxi_SetInputEyeDir(rtx_CubeNormalize(Input.D3_vEye.xyz));
tsxi_SetInputLightDist(tsxi_GetInputEyeDist);
tsxi_SetInputLightDir(tsxi_GetInputEyeDir);
tsxi_SetInputLightColor(RtFloat4(1,1,1,1));
#ifdef RsShaderNORMAL
RtFloat3 vTmpNormal = tsxi_GetInputNormal;
RtFloat3 vTmpTangent = tsxi_GetInputTangent;
RsShaderNORMAL(rsxi_SendShaderInput, vTmpNormal, vTmpTangent);
tsxi_SetInputNormal(normalize(vTmpNormal));
tsxi_SetInputTangent(rtx_CubeNormalize(vTmpTangent));
#else
tsxi_SetInputNormal(rtx_CubeNormalize(tsxi_GetInputNormal));
tsxi_SetInputTangent(rtx_CubeNormalize(tsxi_GetInputTangent));
#endif
#ifdef RsShaderALPHA
RtFloat fTmpAlpha = tsxi_GetInputAlpha;
RsShaderALPHA(rsxi_SendShaderInput, fTmpAlpha);
tsxi_SetInputAlpha(fTmpAlpha);
#endif
#ifdef RsShaderCOLOR
RtFloat4 vTmpColor = tsxi_GetInputColor;
RsShaderCOLOR(rsxi_SendShaderInput, vTmpColor);
tsxi_SetInputColor(vTmpColor);
#endif
RtFloat4 vTmpOutColor = tsxi_GetInputColor;
#ifdef RsShaderMODEL
RsShaderMODEL(rsxi_SendShaderInput, vTmpOutColor);
#else
vTmpOutColor.xyz = tsxi_GetInputColor * tsxi_GetInputLightColor * saturate(dot(tsxi_GetInputLightDir, tsxi_GetInputNormal));
#endif
///We override the color portion here to be used by shadows
float4 output_depth = 0.0f;
if (inShadowQuality == SHADOW_QUALITY_MQ)
{
output_depth = Input.D3_pClipPosition2.z / Input.D3_pClipPosition2.w + fShadowBias;
///If we do MQ shadows then we most probably don't have alpha channel and most probably also no alpha test.
///Therefore we have to kill the pixels manually
clip(vTmpOutColor.a - fKillThresholdValue);
}
else if (inShadowQuality == SHADOW_QUALITY_LQ)
{
float4 vRet;
float fVal = Input.D3_pClipPosition2.z / Input.D3_pClipPosition2.w + fShadowBias;
vRet.x = fVal * 255.0f;
vRet.y = (vRet.x - floor(vRet.x)) * 255.0f;
vRet.z = (vRet.y - floor(vRet.y)) * 255.0f;
vRet.w = (vRet.z - floor(vRet.z)) * 255.0f;
vRet = floor(vRet) / 255.0f;
output_depth = vRet;
}
vTmpOutColor.xyz = output_depth.xyz;
Output.D3_cOutColor = vTmpOutColor;
return Output;
}
pixelshader RsD3DMaterialFromME_Shadow_PixelShader_ps_2_0_LQ = compile ME_PS_PROFILE RsD3DMaterialFromME_Shadow_PixelShader(SHADOW_QUALITY_LQ);
pixelshader RsD3DMaterialFromME_Shadow_PixelShader_ps_2_0_MQ = compile ME_PS_PROFILE RsD3DMaterialFromME_Shadow_PixelShader(SHADOW_QUALITY_MQ);
pixelshader RsD3DMaterialFromME_Shadow_PixelShader_ps_2_0_HQ = compile ME_PS_PROFILE RsD3DMaterialFromME_Shadow_PixelShader(SHADOW_QUALITY_HQ);
vertexshader RsD3DMaterialFromME_Shadow_VertexShader_vs_2_0 = compile ME_VS_PROFILE RsD3DMaterialFromME_Shadow_VertexShader();
//------------------------------
// Shadow Techniques
//------------------------------
//
technique T_ShadowMapHardware
<
string Rs_TechniqueMode = "shadow_hq";
string Rs_TechniqueOpacity = "opaque";
string Rs_TechniqueQuality = "100";
>
{
pass P0
{
VertexShader = (RsD3DMaterialFromME_Shadow_VertexShader_vs_2_0);
PixelShader = (RsD3DMaterialFromME_Shadow_PixelShader_ps_2_0_HQ);
AlphaBlendEnable = false;
ZEnable = true;
ZFunc = LESSEQUAL;
ZWriteEnable = true;
Cullmode = NONE;
}
}
technique T_ShadowMapMQ
<
string Rs_TechniqueMode = "shadow_mq";
string Rs_TechniqueOpacity = "opaque";
string Rs_TechniqueQuality = "75";
>
{
pass P0
{
VertexShader = (RsD3DMaterialFromME_Shadow_VertexShader_vs_2_0);
PixelShader = (RsD3DMaterialFromME_Shadow_PixelShader_ps_2_0_MQ);
AlphaBlendEnable = false;
ZEnable = true;
ZFunc = LESSEQUAL;
ZWriteEnable = true;
Cullmode = NONE;
}
}
technique T_ShadowMapRGBA8
<
string Rs_TechniqueMode = "shadow_lq";
string Rs_TechniqueOpacity = "opaque";
string Rs_TechniqueQuality = "50";
>
{
pass P0
{
VertexShader = (RsD3DMaterialFromME_Shadow_VertexShader_vs_2_0);
PixelShader = (RsD3DMaterialFromME_Shadow_PixelShader_ps_2_0_LQ);
AlphaBlendEnable = false;
ZEnable = true;
ZFunc = LESSEQUAL;
ZWriteEnable = true;
Cullmode = NONE;
}
}